package org.erp.product.controller;

import lombok.AllArgsConstructor;
import lombok.extern.log4j.Log4j2;
import org.erp.common.domain.Result;
import org.erp.product.infrastructure.convert.RepairConvert;
import org.erp.product.domain.entity.RepairLog;
import org.erp.product.domain.bo.RepairLogAddBo;
import org.erp.product.domain.vo.RepairLogVo;
import org.erp.product.service.RepairLogService;
import org.springframework.web.bind.annotation.*;

import java.util.List;

import static org.erp.common.domain.Result.success;

/**
 * 维修记录控制层
 *
 * @author libin
 * @version 1.0
 * @description: 维修记录控制层
 * @date 2025/11/15 19:08
 **/
@Log4j2
@RestController
@AllArgsConstructor
@RequestMapping("/repair/log")
public class RepairLogController {

    private final RepairLogService repairLogService;

    private final RepairConvert repairConvert;

    /**
     * 添加维修记录
     * @param repairLogAddBo
     * @return
     */
    @PostMapping
    public Result<String> save(@RequestBody RepairLogAddBo repairLogAddBo){
        repairLogService.save(repairConvert.boConvertDto(repairLogAddBo));
        return success();
    }

    /**
     * 维修记录列表
     * @return
     */
    @GetMapping
    public Result<List<RepairLogVo>> list(){
        List<RepairLog> list = repairLogService.list();
        return success(list.stream()
                .map(repairConvert::convertVo)
                .toList());
    }
}
